//index.js
//获取应用实例 
var lil = require('../cativity/cativity_a.js')
const app = getApp()

Page({
  xiang: function (a) {
    var dd = a.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/xiangqing/xiangqing?id=' + dd,
    })
  },
  data: {
    lists: [],
    chair: [],
    tea_table: [],
    sofa: [],
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    imgUrls: [
      'http://img.weiye.me/zcimgdir/album/file_58aa94000774b.jpg',
      'http://img.weiye.me/zcimgdir/album/file_58aa970570a50.jpg',
    ],
    indicatorDots: false,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    circular: true
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function() {
    this.setData({
      lists: lil.qqq
    })
    var arr_chair = [],
      arr_teas = [],
      arr_sofa = []
    this.data.lists.forEach(function(item, index) {
      if (item.state == 3) {
        arr_chair.push(item)
      } else if (item.state == 2) {
        arr_teas.push(item)
      } else {
        arr_sofa.push(item)
      }
    })
    this.setData({
      chair: arr_chair
    })
    this.setData({
      tea_table: arr_teas
    })
    this.setData({
      sofa: arr_sofa
    })

    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  xin() {
    wx.navigateTo({
      url: '/pages/xin/xin',
    })
  }
})